﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="util" uri="functions"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
  <script type="text/javascript" src="static/ace/js/jquery.js"></script>
  <link type="text/css" href="static/css/page/bootstrap.min.css" rel="stylesheet" />
  <link type="text/css" href="static/css/page/bootstrap-pagination.min.css" rel="stylesheet" />
    
<!-- jsp文件头和头部 -->
<%@ include file="../index/top.jsp"%>




</head>
<body class="no-skin">

	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">
							
						<!-- 检索  -->
						<form action="admin/createCode/list.do" method="post" name="Form" id="Form">
						<table style="margin-top:5px;width:100%">
							<tr>
								<td style="width:10%">
									<div class="nav-search">
									<span class="input-icon">
										<input type="text" placeholder="这里输入关键词" class="nav-search-input" id="keywords" name="keywords" value="${pd.keywords }" autocomplete="off" />
										<i class="ace-icon fa fa-search nav-search-icon"></i>
									</span>
									</div>
								</td>
								<td style="vertical-align:top;padding-left:2px;width:42px;"><a class="btn btn-light btn-xs" onclick="searchs();"  title="检索"><i id="nav-search-icon" class="ace-icon fa fa-search bigger-110 nav-search-icon blue"></i></a></td>
								<td style="padding-left:20px;"><span class="label label-info arrowed-right arrowed-in">模版生成记录</span></td>
							</tr>
						</table>
						<!-- 检索  -->
					    <div id="div_all_data" v-cloak>
						<table id="simple-table" class="table table-striped table-bordered table-hover" style="margin-top:5px;">	
							<thead>
								<tr>
									<th class="center" style="width:35px;">
									<label class="pos-rel"><input type="checkbox" class="ace" id="zcheckbox" /><span class="lbl"></span></label>
									</th>
									<th class="center" style="width:50px;">序号</th>
									<th class="center">说明</th>
									<th class="center">包名</th>
									<th class="center">类名</th>
									<th class="center">表名</th>
									<th class="center">创建时间</th>
									<th class="center">操作</th>
								</tr>
							</thead>
													
							<tbody>
							<!-- 开始循环 -->	
							<c:choose>
								<c:when test="${not empty totleCount}">
									<c:if test="${util:listAble() }">
										<tr v-for="(item,index) in data">
											<td class='center'>
												<label class="pos-rel"><input type='checkbox' name='ids' :value="item.id" class="ace" /><span class="lbl"></span></label>
											</td>
											<td class='center' style="width: 30px;">{{index + 1}}</td>
													<td class="center">{{item.describe}}</td>
													<td class="center">{{item.packageName}}</td>
													<td class="center">{{item.objectName}}</td>
													<td class="center">{{item.tableName.replace(',fh,', '')}}</td>
													<td class="center">{{item.addDate | time}}</td>
											<td class="center">
												<c:if test="${!util:editAble() && !util:deleteAble() }">
												<span class="label label-large label-grey arrowed-in-right arrowed-in"><i class="ace-icon fa fa-lock" title="无权限"></i></span>
												</c:if>
												<div class="hidden-sm hidden-xs btn-group">
													<c:if test="${util:editAble() }">
													<a class="btn btn-xs btn-success" title="编辑" @click="goEdit(item.id);">
														<i class="ace-icon fa fa-pencil-square-o bigger-120" title="编辑"></i>
													</a>
													</c:if>
													<c:if test="${util:deleteAble() }">
													<a class="btn btn-xs btn-danger" @click="del(item.id);">
														<i class="ace-icon fa fa-trash-o bigger-120" title="删除"></i>
													</a>
													</c:if>
												</div>
											</td>
										</tr>
									
									</c:if>
									<c:if test="${!util:listAble() }">
										<tr>
											<td colspan="100" class="center">您无权查看</td>
										</tr>
									</c:if>
								</c:when>
								<c:otherwise>
									<tr class="main_info">
										<td colspan="100" class="center" >没有相关数据</td>
									</tr>
								</c:otherwise>
							</c:choose>
							</tbody>
						</table>
						</div>
						<div class="page-header position-relative">
						<table style="width:100%;">
							<tr>
								<td style="vertical-align:top;">
									<c:if test="${util:addAble() }">
									<a class="btn btn-mini btn-success" onclick="productCode('add');">启动生成器</a>
									</c:if>
									<c:if test="${util:deleteAble() }">
									<a class="btn btn-mini btn-danger" onclick="makeAll('确定要删除选中的数据吗?');" title="批量删除" ><i class='ace-icon fa fa-trash-o bigger-120'></i></a>
									</c:if>
								</td>
								<!-- 分页的底部 -->
								<td style="vertical-align:top;">
									<nav style="float:right">
								        <ul id="demo1" class="pagination">
								        </ul>
								    </nav>
								 </td>
							</tr>
						</table>
						</div>
						</form>
					
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->


		<!-- 返回顶部 -->
		<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
			<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
		</a>

	</div>
	<!-- /.main-container -->

	<!-- basic scripts -->
	<!-- 页面底部js¨ -->
	<%@ include file="../index/foot.jsp"%>
	<script type="text/javascript" src="static/js/jquery-form.js"></script>
    <script type="text/javascript" charset="utf-8" src="static/js/page/bootstrap-pagination.min.js"></script>
	<!-- 删除时确认窗口 -->
	<script src="static/ace/js/bootbox.js"></script>
	<!-- ace scripts -->
	<script src="static/ace/js/ace/ace.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<script type="text/javascript" src="static/js/vue.js"></script>
	<script type="text/javascript">
		$(top.hangge());//关闭加载状态
		
		//检索
		function searchs(){
			pageData.pageInfo = $('#Form').parseForm();
			 pageList(0, pageData.pageInfo.size, 1);
		}
		//分页数据
	    var pageData = {};
	    pageData.total = '${empty totleCount ? 0:totleCount}';
	    pageData.pageInfo = {};
	    pageData.pageInfo.size =10;
	    pageData.pageInfo.current = 0;
	    pageData.data = [];
	   
	    var pageVm = new Vue({
	        el: '#div_all_data',
	        data: pageData,
	        methods: {
	            goEdit: function (id) {
	            	top.jzts();
	                var diag = new top.Dialog();
	                diag.Drag=true;
	                diag.Title ="代码生成器";
	                diag.URL = '/admin/createCode/goProductCode.do?id='+id;
	                diag.Width = 800;
	                diag.Height = 450;
	                diag.CancelEvent = function(){ //关闭事件
	                   if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
	                	   pageList(0, pageData.pageInfo.size, 1);
	                   }
	                   diag.close();
	                };
	                diag.show();
	            },
	            del: function (id) {
	            	bootbox.confirm("确定要删除吗?", function(result) {
	                    if(result) {
	                        top.jzts();
	                        var url = "/admin/createCode/delete.do?id="+id+"&tm="+new Date().getTime();
	                        $.get(url,function(data){
	                            pageList(0, pageData.pageInfo.size, 1);
	                        });
	                    }
	                });
	            }
	            
	          }
	    })
	    Vue.filter('time',
	    		 <!-- value 格式为13位unix时间戳 -->
	    		 <!-- 10位unix时间戳可通过value*1000转换为13位格式 -->
	    		 function(value) {
	    		 var date = new Date(value);
	    		 Y = date.getFullYear(),
	    		 m = date.getMonth() + 1,
	    		 d = date.getDate(),
	    		 H = date.getHours(),
	    		 i = date.getMinutes(),
	    		 s = date.getSeconds();
	    		 if (m < 10) {
	    		  m = '0' + m;
	    		 }
	    		 if (d < 10) {
	    		  d = '0' + d;
	    		 }
	    		 if (H < 10) {
	    		  H = '0' + H;
	    		 }
	    		 if (i < 10) {
	    		  i = '0' + i;
	    		 }
	    		 if (s < 10) {
	    		  s = '0' + s;
	    		 }
	    		 <!-- 获取时间格式 2017-01-03 10:13:48 -->
	    		  var t = Y+'-'+m+'-'+d+' '+H+':'+i+':'+s;
	    		 <!-- 获取时间格式 2017-01-03 -->
	    		 //var t = Y + '-' + m + '-' + d;
	    		 return t;
	    		 })
		$(function() {
			$(".input-group").hide();
			//初始化第一页数据
			pageList( pageData.pageInfo.current, pageData.pageInfo.size);
			//分页控制
            initBootstrap(parseInt(pageData.total));
			//复选框全选控制
			var active_class = 'active';
			$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function(){
				var th_checked = this.checked;//checkbox inside "TH" table header
				$(this).closest('table').find('tbody > tr').each(function(){
					var row = this;
					if(th_checked) $(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
					else $(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
				});
			});
			
		});
	    
	    function initBootstrap(total){
	    	 var demo1 = BootstrapPagination($("#demo1"), {
                 //记录总数。 
                 total: total,
                 //当前页索引编号。从其开始（从0开始）的整数。
                 pageIndex: 0,
                 pageGroupSize: 5,
                 pageSize: 10,
                 //当分页更改后引发此事件。
                 pageChanged: function (pageIndex, pageSize) {
                     pageList(pageIndex, pageSize, 2);
                 },
             }); 
	    }
		//分页查询
	    function pageList(pageIndex, pageSize, type){
	    	pageData.pageInfo.current = ((pageIndex - 0) +1);
            pageData.pageInfo.size = pageSize;
            $.post("/admin/createCode/list", pageData.pageInfo, function(result){
                if (result.code == 200){
                	pageData.data = [];
                    var resultData = result.data.data;
                    pageData.total = result.data.total;
                    if(type == 1){
                    	initBootstrap(parseInt(result.data.total));
                    }
                    for (var i = 0; i < resultData.length; i++){
                        pageData.data.push(resultData[i]);
                    }
                }
            })
            $(top.hangge());
	    }
	    
		//启动代码生成器
		function productCode(id){
			top.jzts();
            var diag = new top.Dialog();
            diag.Drag=true;
            diag.Title ="代码生成器";
            diag.URL = '/admin/createCode/goProductCode.do?id='+id;
            diag.Width = 800;
            diag.Height = 450;
            diag.CancelEvent = function(){ //关闭事件
               if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
            	   pageList(0, pageData.pageInfo.size, 1);
               }
               diag.close();
            };
            diag.show();
		}
		
		
		//修改
		function edit(Id){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="编辑";
			 diag.URL = '/admin/createcode/goEdit.do?id='+Id;
			 diag.Width = 450;
			 diag.Height = 355;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('zhongxin').style.display == 'none'){
					 pageList(0, pageData.pageInfo.size, 1);
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++){
					  if(document.getElementsByName('ids')[i].checked){
					  	if(str=='') str += document.getElementsByName('ids')[i].value;
					  	else str += ',' + document.getElementsByName('ids')[i].value;
					  }
					}
					if(str==''){
						bootbox.dialog({
							message: "<span class='bigger-110'>您没有选择任何内容!</span>",
							buttons: 			
							{ "button":{ "label":"确定", "className":"btn-sm btn-success"}}
						});
						$("#zcheckbox").tips({
							side:1,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							top.jzts();
							$.ajax({
								type:"POST",
								url:'/admin/createCode/deleteAll.do?tm='+new Date().getTime(),
						    	data:{ids:str},
								dataType:'json',
								//beforeSend: validateData,
								cache:false,
								success:function(data){
									 pageList(0, pageData.pageInfo.size, 1);
								}
							});
						}
					}
				}
			});
		};
	</script>

<tags:loading></tags:loading>
</body>
</html>